home *** CD-ROM | disk | FTP | other *** search
- Path: gate.net!pslfl2-38
- From: bhutto@gate.net (William Hutto)
- Newsgroups: comp.lang.c
- Subject: Re: Help: crash when doing fprintf
- Date: 15 Jan 1996 10:13:20 GMT
- Organization: CyberGate, Inc.
- Message-ID: <4dd9c0$11lo@news.gate.net>
- References: <DL74rA.L5v@info.physics.utoronto.ca>
- NNTP-Posting-Host: pslfl2-38.gate.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <DL74rA.L5v@info.physics.utoronto.ca>,
- olivers@helios.physics.utoronto.ca (Oliver Schonborn) wrote:
- >
- >Hello folks!
- >
- >My program crashes when it executes the following statements:
- >
- > char frootn[200]=".",
- > fout[200] ="";
- > float time;
- > FILE *fp;
-
- How much stack do you have allocated? Have you tried defining some of your
- locals (especially large ones) static?
-
-
- > ....
- > sprintf(fout,"%s/test%-.5g",frootn,time);
- > printf("Outputting to %s...\n",fout);
- > fp=fopen(fout,"w");
-
- I have to figure you've tested this in a debugger and know that fp != NULL,
- but do you know the internal representation of NULL on your machine? No reason
- not to test this FILE * in your code.
-
- > fprintf(fp,"Hello\n");
- >
- >This is what fp points to at crash time:
- >
- >0x40001038 struct FILE {
- > __cnt = 0;
- > __ptr = 00000000;
- > __base = 00000000;
- > __flag = 2;
- > __fileL = 3;
- > __fileH = 0;
- >}
- >
- >It crashes deep inside the fprintf. A trace with the debugger
- >indicates where (main called _fprintf which called _wrtchk which
- >called _findbuf which called malloc):
- >
- > 0 malloc@libc + 0x00000470 (0x7b012538, 0x7b011168, 0x7b011164, 0x7b011160)
- > 1 _findbuf@libc + 0x000000fc (0x160, 0x8, 0x160, 0x7b0335b0)
- > 2 _wrtchk@libc + 0x00000058 (0x40061f40, 0x40061d38, 0x40061938, 0x3f7b53d2)
- > 3 _fprintf@libc + 0x00000024 (0x3c23d71a, 0x7b0336e4, 0x7b014e60,
- 0x7b014e6c)
- > 4 main (argc = 3, argv = 0x7b033494) [sfbynorm.c: 556]
- >
- >I've never seen anything like that bug before. I used gcc 2.7.1
- >with -Wall -pedantic and get no warnings whatsoever. With lint the
- >only warning I get is a possible pointer alignment problem from the
- >2 lines which define (and initialize) frootn[] and fout[], though I
- >don't know whether I should take that seriously.
- >
- >Anybody have any clue? Thanks for any help,
- >
- >Oliver
-
-
- Bill
-
- "Whatcha got on?...Your mind?"
-